home *** CD-ROM | disk | FTP | other *** search
/ Programming Microsoft Visual Basic .NET / Programming Microsoft Visual Basic .NET (Microsoft Press)(X08-78517)(2002).bin / 17 controls / controlsdemo / providercontrolsform.vb < prev    next >
Encoding:
Text File  |  2002-03-16  |  6.8 KB  |  172 lines

  1. Public Class ProviderControlsForm
  2.     Inherits System.Windows.Forms.Form
  3.  
  4. #Region " Windows Form Designer generated code "
  5.  
  6.     Public Sub New()
  7.         MyBase.New()
  8.  
  9.         'This call is required by the Windows Form Designer.
  10.         InitializeComponent()
  11.  
  12.         'Add any initialization after the InitializeComponent() call
  13.  
  14.     End Sub
  15.  
  16.     'Form overrides dispose to clean up the component list.
  17.     Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
  18.         If disposing Then
  19.             If Not (components Is Nothing) Then
  20.                 components.Dispose()
  21.             End If
  22.         End If
  23.         MyBase.Dispose(disposing)
  24.     End Sub
  25.     Friend WithEvents ToolTip1 As System.Windows.Forms.ToolTip
  26.             Friend WithEvents ErrorProvider1 As System.Windows.Forms.ErrorProvider
  27.     Friend WithEvents HelpProvider1 As System.Windows.Forms.HelpProvider
  28.     Friend WithEvents Label1 As System.Windows.Forms.Label
  29.     Friend WithEvents Label2 As System.Windows.Forms.Label
  30.     Friend WithEvents btnOK As System.Windows.Forms.Button
  31.     Friend WithEvents btnCancel As System.Windows.Forms.Button
  32.     Friend WithEvents txtProduct As System.Windows.Forms.TextBox
  33.     Friend WithEvents txtQty As System.Windows.Forms.TextBox
  34.     Private components As System.ComponentModel.IContainer
  35.  
  36.     'Required by the Windows Form Designer
  37.     
  38.     'NOTE: The following procedure is required by the Windows Form Designer
  39.     'It can be modified using the Windows Form Designer.  
  40.     'Do not modify it using the code editor.
  41.     <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
  42.         Me.components = New System.ComponentModel.Container()
  43.         Me.txtQty = New System.Windows.Forms.TextBox()
  44.         Me.ToolTip1 = New System.Windows.Forms.ToolTip(Me.components)
  45.         Me.txtProduct = New System.Windows.Forms.TextBox()
  46.         Me.btnOK = New System.Windows.Forms.Button()
  47.         Me.btnCancel = New System.Windows.Forms.Button()
  48.         Me.HelpProvider1 = New System.Windows.Forms.HelpProvider()
  49.         Me.Label1 = New System.Windows.Forms.Label()
  50.         Me.Label2 = New System.Windows.Forms.Label()
  51.         Me.ErrorProvider1 = New System.Windows.Forms.ErrorProvider()
  52.         Me.SuspendLayout()
  53.         '
  54.         'txtQty
  55.         '
  56.         Me.HelpProvider1.SetHelpString(Me.txtQty, "Insert the number of products to be order. It must be a number in the range 1-100" & _
  57.         ".")
  58.         Me.txtQty.Location = New System.Drawing.Point(28, 80)
  59.         Me.txtQty.Name = "txtQty"
  60.         Me.HelpProvider1.SetShowHelp(Me.txtQty, True)
  61.         Me.txtQty.Size = New System.Drawing.Size(248, 24)
  62.         Me.txtQty.TabIndex = 3
  63.         Me.txtQty.Text = ""
  64.         Me.ToolTip1.SetToolTip(Me.txtQty, "The number of products ordered")
  65.         '
  66.         'txtProduct
  67.         '
  68.         Me.HelpProvider1.SetHelpString(Me.txtProduct, "Enter the name of the product. This field can't be empty.")
  69.         Me.txtProduct.Location = New System.Drawing.Point(28, 32)
  70.         Me.txtProduct.Name = "txtProduct"
  71.         Me.HelpProvider1.SetShowHelp(Me.txtProduct, True)
  72.         Me.txtProduct.Size = New System.Drawing.Size(248, 24)
  73.         Me.txtProduct.TabIndex = 1
  74.         Me.txtProduct.Text = ""
  75.         Me.ToolTip1.SetToolTip(Me.txtProduct, "The name of the product")
  76.         '
  77.         'btnOK
  78.         '
  79.         Me.btnOK.Location = New System.Drawing.Point(68, 120)
  80.         Me.btnOK.Name = "btnOK"
  81.         Me.btnOK.Size = New System.Drawing.Size(72, 32)
  82.         Me.btnOK.TabIndex = 4
  83.         Me.btnOK.Text = "OK"
  84.         Me.ToolTip1.SetToolTip(Me.btnOK, "Click here to confirm the order")
  85.         '
  86.         'btnCancel
  87.         '
  88.         Me.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel
  89.         Me.btnCancel.Location = New System.Drawing.Point(164, 120)
  90.         Me.btnCancel.Name = "btnCancel"
  91.         Me.btnCancel.Size = New System.Drawing.Size(72, 32)
  92.         Me.btnCancel.TabIndex = 5
  93.         Me.btnCancel.Text = "Cancel"
  94.         Me.ToolTip1.SetToolTip(Me.btnCancel, "Click here to cancel the order")
  95.         '
  96.         'Label1
  97.         '
  98.         Me.Label1.Location = New System.Drawing.Point(32, 16)
  99.         Me.Label1.Name = "Label1"
  100.         Me.Label1.Size = New System.Drawing.Size(120, 16)
  101.         Me.Label1.TabIndex = 0
  102.         Me.Label1.Text = "Product"
  103.         '
  104.         'Label2
  105.         '
  106.         Me.Label2.Location = New System.Drawing.Point(32, 64)
  107.         Me.Label2.Name = "Label2"
  108.         Me.Label2.Size = New System.Drawing.Size(120, 16)
  109.         Me.Label2.TabIndex = 2
  110.         Me.Label2.Text = "Quantity"
  111.         '
  112.         'ErrorProvider1
  113.         '
  114.         Me.ErrorProvider1.DataMember = Nothing
  115.         '
  116.         'ProviderControlsForm
  117.         '
  118.         Me.AcceptButton = Me.btnOK
  119.         Me.AutoScaleBaseSize = New System.Drawing.Size(7, 17)
  120.         Me.CancelButton = Me.btnCancel
  121.         Me.ClientSize = New System.Drawing.Size(312, 165)
  122.         Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.btnCancel, Me.btnOK, Me.Label2, Me.Label1, Me.txtQty, Me.txtProduct})
  123.         Me.Font = New System.Drawing.Font("Microsoft Sans Serif", 11!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
  124.         Me.Name = "ProviderControlsForm"
  125.         Me.Text = "ProviderControls demo"
  126.         Me.ResumeLayout(False)
  127.  
  128.     End Sub
  129.  
  130. #End Region
  131.  
  132.     ' display error icon near all controls that didn't validate
  133.  
  134.     Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
  135.         ' assume it's ok to close the form.
  136.         Me.DialogResult = DialogResult.OK
  137.  
  138.         ' clear all error icons.
  139.         ErrorProvider1.SetError(txtProduct, "")
  140.         ErrorProvider1.SetError(txtQty, "")
  141.  
  142.         ' validate the txtProduct control
  143.  
  144.         If txtProduct.Text = "" Then
  145.             ErrorProvider1.SetError(txtProduct, "Must enter a product name")
  146.             Me.DialogResult = DialogResult.None
  147.         End If
  148.  
  149.         ' validate the txtQty field
  150.  
  151.         Try
  152.             ' Attempt to get a valid quantity.
  153.             Dim qty As Integer = CInt(txtQty.Text)
  154.             ' Thown any error if out of range.
  155.             If qty < 1 Or qty > 100 Then Throw New Exception()
  156.         Catch
  157.             ' Regardless of the error, use the same error message.
  158.             ErrorProvider1.SetError(txtQty, "Enter a valid number in range 1-100")
  159.             Me.DialogResult = DialogResult.None
  160.         End Try
  161.  
  162.         ' exit only if DialogResult wasn't reset
  163.         If Me.DialogResult = DialogResult.OK Then Me.Close()
  164.     End Sub
  165.  
  166.     ' close anyway when clicking on the Cancel button
  167.  
  168.     Private Sub btnCancel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCancel.Click
  169.         Me.Close()
  170.     End Sub
  171. End Class
  172.